import dayjs from 'dayjs'

export default function directiveFtime(app) {
	app.directive('ftime', {
		mounted(el, bindings) {
			let timestamp = el.textContent
			// 获取时间， 并且转换为毫秒
			if (timestamp.length === 10) {
				timestamp = timestamp * 1000
			}

			timestamp = Number(timestamp)

			let formatStr = bindings.value || 'YYYY-MM-DD'
			// 对时间进行格式化
			const formatTime = dayjs(timestamp).format(formatStr)
			el.textContent = formatTime
		},
	})
}
